import 'package:freezed_annotation/freezed_annotation.dart';

part 'af_edit_user_param_model.freezed.dart';
part 'af_edit_user_param_model.g.dart';

@freezed
class AfEditUserParamModel with _$AfEditUserParamModel {
  factory AfEditUserParamModel({
    @JsonKey(name: 'avatar_path') String? avatarPath,
    String? name,
    @JsonKey(name: 'birth_date') String? birthDate,
  }) = _AfEditUserParamModel;

  factory AfEditUserParamModel.fromJson(Map<String, dynamic> json) =>
      _$AfEditUserParamModelFromJson(json);
}

extension AfEditUserParamModelExt on AfEditUserParamModel {
  DateTime get birthdayDate {
    if (birthDate != null && birthDate!.split('-').length == 3) {
      final List<String> list = birthDate!.split('-');
      return DateTime(
          int.parse(list[0]), int.parse(list[1]), int.parse(list[2]));
    }
    return DateTime(1990, 01, 01);
  }
}
